@{
	WebSecurity.RequireAuthenticatedUser();
    if (!Roles.IsUserInRole("Admin")) {
    	Response.Redirect("~");
    }
}

<h1>Poll Results</h1>
<img class="leftchart" src="@Href("~/Admin/PollChart/4252270?type=pie&width=440&height=300")"/>
<img class="rightchart" src="@Href("~/Admin/PollChart/4252270?type=bar&width=450&height=300")"/>

<h2>Poll comments: </h2>
@{
    // Example of how to use the Polldaddy helper with the WebMatrix WebGrid helper
    var comments = Polldaddy.GetPollComments("4252270");
	WebGrid grid = new WebGrid(comments, rowsPerPage: 5);
}

@grid.GetHtml(
		tableStyle: "box",
		headerStyle: "q-report-head",
		columns: grid.Columns(
			grid.Column("Date", format:@<div>@item.date</div>),
			grid.Column("Name/Email",format: @<div class="comment-name">
							@item.name <br> <a href="mailto:@item.email">@item.email</a></div>),
			grid.Column("Comment", format: @<div class="comment-text" >@item.text</div>),
			grid.Column(columnName: "Status", header: "Status", format:
				@<text>
					@if (@item.type == "0") {
							<div>To moderate</div>
					} else {
						if (@item.type == "1") {
							<div class="comment-name">Accepted</div>
						} else {
							<div class="comment-deleted">Rejected</div>
						}
					}
					</text>
				)
			)
		)

<div class="code">
    <p><strong>Polldaddy Helper Code Used in this Page</strong></p>
    <p>For showing the poll comments using the WebGrid:</p>
    <pre class="codePre">@@{
    var comments = Polldaddy.GetPollComments("4252270");
    WebGrid grid = new WebGrid(comments, rowsPerPage: 5);
}
@@grid.GetHtml(...)</pre>
    <p>For showing the poll results using the Chart helper you need to create a separate page with the following code 
       to return the chart image, and then use an IMG element to show it: </p>
    <pre class="codePre">
@@{
   var poll = Polldaddy.GetPoll(pollId);       
   var results = Polldaddy.GetPollResults(pollId);
    
   string[] xValues = results.Select(r => (string)r.text).ToArray();
   int[] yValues = results.Select(r => int.Parse((string)r.total)).ToArray();
    
   var chart = new Chart(width: width, height: height, theme: ChartTheme.Yellow)
        .AddTitle(poll.question)
        .AddSeries("Default", chartType: chartType,
                    xValue: xValues, xField: "Text",
                    yValues: yValues, yFields: "Total")
        .Write();
}
</pre>
<pre class="codePre">
&lt;img class="rightchart" src="@@Href("~/Admin/PollChart/4252270")"/&gt;
</pre>   
</div>
